<?php

Yii::import('application.models._base.BaseRegions');

class Regions extends BaseRegions
 {
	public static function model($className=__CLASS__) {
		return parent::model($className);
	}
    
	public function beforeSave() {
	    if ($this->isNewRecord) {
            if ($this->hasAttribute('crdate')) {
                $this->crdate = time();
            }
		}
        if ($this->hasAttribute('slug')) {
            if ('' == $this->slug) $this->slug = $this->makeSlug($this->name);    
        }          
	    return parent::beforeSave();
	}	    
    
    public function scopes() {
        return array(
            'visible'=>array(
                'condition'=>'t.hidden=0',
            ),
			'hidden' =>array(
                'condition'=>'t.hidden=1',
			),
            'by_id_desc'=>array(
                'order'=>'t.id DESC',
            ),
            'by_id_asc'=>array(
                'order'=>'t.id ASC',
            ),
		);
    }	
}